package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.mapper.UserMapper;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Override
    public List<User> findAll() {
        return userMapper.findAll();
    }

    @Override
    public boolean add(User user) {


        try {
            userMapper.add(user);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;

    }

    @Override
    public boolean deleteById(Integer id) {
        try {
            userMapper.deleteById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }
    @Override
    public void updateUser(User user) {
        userMapper.updateUser(user);
    }

    @Override
    public List<User> queryByPage(Integer current, Integer size, String condition) {

        PageHelper.startPage(current,size);
        Page<User> pages =  userMapper.queryByPage(condition);
        return pages;
    }
}
